package com.woniu.smart.security;

import com.woniu.smart.entity.SysAdmin;
import com.woniu.smart.service.SysAdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @Description: TODO
 * @Author: WangHeng
 * @Date: 2022/10/24 18:14
 */
@Service
@Slf4j
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private SysAdminService userService;


    @Override
    //这里的username就是我的账户tel
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        LoginUser loginUser = new LoginUser();
        //根据账号返回实体对象
        SysAdmin sysAdmin = userService.login(username);
        loginUser.setSysAdmin(sysAdmin);
        return loginUser;
    }
}
